import tkinter as tk
from tkinter import ttk
import json

# 定义JSON格式的测试数据
test_data_json = [
    {"用户名称": "张三", "账号": "123", "邮箱地址": "123@hotmail.com"},
    {"用户名称": "李四", "账号": "456", "邮箱地址": "456@hotmail.com"},
    {"用户名称": "王五", "账号": "789", "邮箱地址": "789@hotmail.com"},
    {"用户名称": "赵六", "账号": "101", "邮箱地址": "101@hotmail.com"},
    {"用户名称": "孙七", "账号": "111", "邮箱地址": "111@hotmail.com"},
    {"用户名称": "周八", "账号": "222", "邮箱地址": "222@hotmail.com"},
    {"用户名称": "吴九", "账号": "333", "邮箱地址": "333@hotmail.com"},
    {"用户名称": "郑十", "账号": "444", "邮箱地址": "444@hotmail.com"},
    {"用户名称": "陈十一", "账号": "555", "邮箱地址": "555@hotmail.com"},
    {"用户名称": "杨十二", "账号": "666", "邮箱地址": "666@hotmail.com"}
]

root = tk.Tk()
root.title("用户信息表格")

# 创建样式对象
style = ttk.Style()
style.configure("Treeview", borderwidth=1, relief="solid", rowheight=25)

# 创建搜索框框架
search_frame = tk.Frame(root)
search_frame.pack(anchor='nw', padx=10, pady=10)

# 创建搜索框
search_var = tk.StringVar()
search_entry = tk.Entry(search_frame, textvariable=search_var)
search_entry.pack(side='left')

# 搜索功能函数
def search():
    keyword = search_var.get()
    tree.delete(*tree.get_children())
    for data in test_data_json:
        for value in data.values():
            if keyword.lower() in str(value).lower():
                tree.insert("", tk.END, values=(data["用户名称"], data["账号"], data["邮箱地址"]))
                break

# 创建搜索按钮
search_button = tk.Button(search_frame, text="搜索", command=search)
search_button.pack(side='left', padx=5)

# 创建Treeview组件
tree = ttk.Treeview(root, columns=("用户名称", "账号", "邮箱地址"), show='headings', style="Treeview")

# 设置列标题
tree.heading("用户名称", text="用户名称")
tree.heading("账号", text="账号")
tree.heading("邮箱地址", text="邮箱地址")

# 填充测试数据
for data in test_data_json:
    tree.insert("", tk.END, values=(data["用户名称"], data["账号"], data["邮箱地址"]))

tree.pack()

root.mainloop()